package com.yyfax.ph.home.imageupload;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.yyfax.ph.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称：YYLending
 * 类描述：
 * 创建人：xiongyufeng
 * 创建时间：2016/11/17 18:08
 * 修改人：xiongyufeng
 * 修改时间：2016/11/17 18:08
 * 修改备注：
 */
public class ChooseImageDialog extends Dialog {
	@BindView(R.id.preview_tv)
	TextView mPreviewTv;

	private boolean mPreViewFlag = false;
	private SelectImageListener mSelectImageListener;

	public ChooseImageDialog(Context context, SelectImageListener listener, boolean showPreViewFlag) {
		super(context);
		mPreViewFlag = showPreViewFlag;
		this.mSelectImageListener = listener;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.choose_image_dialog_layout);
		ButterKnife.bind(this);
		initWindowParams();
		initView();
	}

	private void initWindowParams() {
		Window window = getWindow();
		if (window != null) {
			window.setBackgroundDrawableResource(android.R.color.transparent);
			window.setGravity(Gravity.BOTTOM);
			window.setWindowAnimations(R.style.AnimBottom);
			window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
		}
	}

	private void initView() {
		if (mPreViewFlag) {
			mPreviewTv.setVisibility(View.VISIBLE);
		} else {
			mPreviewTv.setVisibility(View.GONE);
		}
	}

	@OnClick({R.id.preview_tv, R.id.take_picture_tv, R.id.choose_photo_tv, R.id.ll_cancel})
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.preview_tv:
				if (null != mSelectImageListener) {
					mSelectImageListener.onSelectImageChoose(0);
				}
				break;
			case R.id.take_picture_tv:
				if (null != mSelectImageListener) {
					mSelectImageListener.onSelectImageChoose(1);
				}
				break;
			case R.id.choose_photo_tv:
				if (null != mSelectImageListener) {
					mSelectImageListener.onSelectImageChoose(2);
				}
				break;
			case R.id.ll_cancel:
				break;
		}
		dismiss();
	}

	public interface SelectImageListener {
		void onSelectImageChoose(int type);
	}

}

